
import {ref,reactive} from 'vue'
export default  function usePageList(api,data){
    let apiData=reactive(data)
    let loading=ref(false)
    let finished=ref(false)
    let list=ref([])
    let onLoad= async()=>{
      
        let res = await api(apiData)
       
        apiData.page++
        if(res.data.list){
            list.value.push(...res.data.list)
        }
        if(apiData.page>Math.ceil(res.data.count/apiData.limit)){
            finished.value=true
        }
       
        loading.value=false
        
    }
   
    return {
        onLoad,
        loading,
        finished,
        list
    }
}
